<?php
// +----------------------------------------------------------------------
// | 商家模块
// +----------------------------------------------------------------------

namespace app\mall\model;

use think\Model as ThinkModel;
use util\Tree;
use think\facade\Db;

/**
 * 证书模型
 * @package app\mall\model
 */
class Cert extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'mall_cert';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;


    /**
     * 获取证书列表
     * @return array|mixed
     */
    public static function getList()
    {
        $data_list = cache('cert_list');
        if (!$data_list) {
            $data_list = self::where('status', 1)->order('sort')->column(true, 'id');
            // 非开发模式，缓存数据
            if (config('app.develop_mode') == 0) {
                cache('cert_list', $data_list);
            }
        }
        return $data_list;
    }
	
	/**
	 * 获取简单证书列表
	 * @return array|mixed
	 */
	public static function getColumn()
	{
	    $data_list = cache('cert_column');
	    if (!$data_list) {
	        $data_list = self::where('status', 1)->order('sort')->column('serial_no', 'id');
	        // 非开发模式，缓存数据
	        if (config('app.develop_mode') == 0) {
	            cache('cert_column', $data_list);
	        }
	    }
	    return $data_list;
	}
	
    /**
     * 获取指定证书数据
     * @param int $id 证书id
     * @return mixed|static
     */
    public static function getInfo($id = 0)
    {
        $result = cache('cert_info_'. $id);
        if (!$result) {
            $result = self::where('id', $id)->find();
            // 非开发模式，缓存数据
            if (config('app.develop_mode') == 0) {
                cache('cert_info_'. $id, $result);
            }
        }
        return $result;
    }

}